package cn.hu.basic.service.impl;

import cn.hu.basic.util.PageList;
import cn.hu.basic.mapper.BaseMapper;
import cn.hu.basic.query.BaseQuery;
import cn.hu.basic.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;


    @Override
    public T findById(Long id) {
        return mapper.findById(id);
    }

    @Override
    public List<T> findAll() {
        return mapper.findAll();
    }

    @Override
    @Transactional
    public void add(T t) {
        mapper.add(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public PageList<T> listByQuery(BaseQuery query) {
        return new PageList<>(mapper.queryCount(query),mapper.queryData(query));
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        mapper.patchDelete(ids);
    }
}
